<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="LINE" />
<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="MULTILINE" />
<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="DROPDOWN_LIST" />
<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="RADIO_BUTTONS" />
<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="CHECK_BOXES" />
<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="MULTILIST" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="HTML_TEXT_FIELD_MAX_LENGTH" />
<atleap:constants className="com.blandware.atleap.webapp.util.questionnaire.QuestionnaireModuleWebConstants" var="NOTHING_SELECTED_OPTION_ID" />
<atleap:constants className="com.blandware.atleap.webapp.util.questionnaire.QuestionnaireModuleWebConstants" var="CHECKBOX_ID_DELIMITER" />
<%--<atleap:javascript formName="questionForm" staticJavascript="false" dynamicJavascript="true" method="validateForm" cdata="false" />--%>

<atleap:fieldValue valueMap="${questionnaire.annotation}" filter="false" />

<atleap:form action="questionnaire/questionnaire/fill" method="POST" validateOnSubmit="false">
    <atleap:messages property="questionnaireNotFound" />
    <atleap:messages property="ownerNotFound" />
    <atleap:messages property="fillRequiredFields" />
    <atleap:messages property="illegalText" />
    <atleap:messages property="success" />
    <atleap:message key="questionnaire.questionnaire.form.nothingSelected" var="nothingSelectedMsg" />
    <table cellpadding="0"  cellspacing="0" border="0" class="modificationTable">
        <atleap:iterator items="${requestScope.questionnaire.questions}" var="question">
            <tr>
                <c:choose>
                    <c:when test="${question.type == LINE}">
                        <th>
                            <atleap:label property="textQuestion(${question.id})" helpTip="true" colon="false">
                                <c:if test="${question.required}">*</c:if>
                                <atleap:fieldValue valueMap="${question.title}" filter="false" />
                            </atleap:label>
                        </th>
                        <td>
                            <html:text property="textQuestion(${question.id})" maxlength="${pageScope.HTML_TEXT_FIELD_MAX_LENGTH}" styleClass="text" />
                        </td>
                    </c:when>
                    <c:when test="${question.type == MULTILINE}">
                        <th>
                            <atleap:label property="textQuestion(${question.id})" helpTip="true" colon="false">
                                <c:if test="${question.required}">*</c:if>
                                <atleap:fieldValue valueMap="${question.title}" filter="false" />
                            </atleap:label>
                        </th>
                        <td>
                            <html:textarea property="textQuestion(${question.id})" styleClass="multilineQuestion" />
                        </td>
                    </c:when>
                    <c:when test="${question.type == DROPDOWN_LIST}">
                        <th>
                            <atleap:label property="intQuestion(${question.id})" helpTip="true" colon="false">
                                <c:if test="${question.required}">*</c:if>
                                <atleap:fieldValue valueMap="${question.title}" filter="false" />
                            </atleap:label>
                        </th>
                        <td>
                            <html:select property="intQuestion(${question.id})">
                                <c:if test="${!question.required}">
                                    <html:option value="${pageScope.NOTHING_SELECTED_OPTION_ID}">
                                        ${nothingSelectedMsg}
                                    </html:option>
                                </c:if>
                                <atleap:iterator items="${question.answerOptions}" var="answerOption">
                                    <html:option value="${answerOption.id}">
                                        <atleap:fieldValue valueMap="${answerOption.title}" filter="true" />
                                    </html:option>
                                </atleap:iterator>
                            </html:select>
                        </td>
                    </c:when>
                    <c:when test="${question.type == RADIO_BUTTONS}">
                        <th>
                            <atleap:label property="intQuestion(${question.id})" helpTip="true" colon="false">
                                <c:if test="${question.required}">*</c:if>
                                <atleap:fieldValue valueMap="${question.title}" filter="false" />
                            </atleap:label>
                        </th>
                        <td>
                            <atleap:iterator items="${question.answerOptions}" var="answerOption">
                                <html:radio property="intQuestion(${question.id})"  value="${answerOption.id}">
                                    <atleap:fieldValue valueMap="${answerOption.title}" filter="true" /><br />
                                </html:radio>
                            </atleap:iterator>
                        </td>
                    </c:when>
                    <c:when test="${question.type == CHECK_BOXES}">
                        <th>
                            <atleap:label property="checkboxQuestion(${question.id})" helpTip="true" colon="false">
                                <c:if test="${question.required}">*</c:if>
                                <atleap:fieldValue valueMap="${question.title}" filter="false" />
                            </atleap:label>
                        </th>
                        <td>
                            <atleap:iterator items="${question.answerOptions}" var="answerOption">
                                <html:checkbox property="checkboxQuestion(${question.id}${pageScope.CHECKBOX_ID_DELIMITER}${answerOption.id})" styleClass="checkbox" />
                                <atleap:fieldValue valueMap="${answerOption.title}" filter="true" />
                                <br />
                            </atleap:iterator>
                        </td>
                    </c:when>
                    <c:when test="${question.type == MULTILIST}">
                        <th>
                            <atleap:label property="multiIntQuestion(${question.id})" helpTip="true" colon="false">
                                <c:if test="${question.required}">*</c:if>
                                <atleap:fieldValue valueMap="${question.title}" filter="false" />
                            </atleap:label>
                        </th>
                        <td>
                            <html:select property="multiIntQuestion(${question.id})" multiple="true" size="5">
                                <atleap:iterator items="${question.answerOptions}" var="answerOption">
                                    <html:option value="${answerOption.id}">
                                        <atleap:fieldValue valueMap="${answerOption.title}" filter="true" />
                                    </html:option>
                                </atleap:iterator>
                            </html:select>
                        </td>
                    </c:when>
                </c:choose>
            </tr>
        </atleap:iterator>
    </table>
    <html:hidden property="id" />

    <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.submit" /></atleap:submit>
    <atleap:cancel styleClass="button"><atleap:message key="core.commons.buttons.cancel" /></atleap:cancel>
</atleap:form>
